package fr.cnam.ratpProject.client.activities.searchStation;

import java.util.ArrayList;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.googlecode.mgwt.ui.client.widget.ScrollPanel;

import fr.cnam.ratpProject.client.css.AppBundle;
import fr.cnam.ratpProject.client.utils.RatpCommand;
import fr.cnam.ratpProject.sharedDatas.Ligne;
import fr.cnam.ratpProject.sharedDatas.Station;

public class LinePanel extends AbsolutePanel{

	private ScrollPanel imgPanel = new ScrollPanel();
	
	
	private ArrayList<StationPanel> pnlStations = new ArrayList<StationPanel>();
	
	private RatpCommand<Station> stationCommand = null;
	
	private int pxToAdd = 0;
	
	private Label test = new Label();
	
	private class StationPanel extends FocusPanel
	{
		private Station station;
		
		public StationPanel(final Station station)
		{
			this.station = station;
			setSize("60px", "60px");
			
			addClickHandler(new ClickHandler() {
				
				@Override
				public void onClick(ClickEvent event) {
					if(stationCommand !=null)
						stationCommand.execute(StationPanel.this.station);
				}
			});
		}
		
		

		public Station getStation() {
			return station;
		}

		public void setStation(Station station) {
			this.station = station;
		}
	}
	
	public LinePanel() {
		super();
		this.setSize("3000px","860px");
		imgPanel.setSize("400px", "600px");
		imgPanel.add(new Image(AppBundle.INSTANCE.ligne14()));
		imgPanel.setScrollingEnabledX(true);
		imgPanel.setShowScrollBarX(true);
		this.add(imgPanel, 0,0);
		
	}
	public LinePanel(Ligne ligne)
	{
		super();
		this.setSize("3000px","860px");
//		this();
		setStations(ligne);
		
	}

	
	public void setStations(Ligne ligne)
	{
		if(ligne !=null)
		{
			Image img = getImage(ligne.getIdLigne());
			imgPanel.add(new Image(AppBundle.INSTANCE.ligne14()));
			
			imgPanel.setScrollingEnabledX(true);
			imgPanel.setShowScrollBarX(true);
			this.add(imgPanel, 0,0);
//			for(Station station:ligne.getLigne())
//			{
//				StationPanel pnl = new StationPanel(station);
//				this.add(pnl, station.getPosXLine() - 20, station.getPosYLine()-20);//51,465
//				pnlStations.add(pnl);
//			}
		}
	}
	
	private Image getImage(String id)
	{
		Image img = null;
		
		if(id.equals("1"))
		{
			img = new Image(AppBundle.INSTANCE.ligne1());
		}
		else if(id.equals("2"))
		{
			img = new Image(AppBundle.INSTANCE.ligne2());
		}
		else if(id.equals("3") || id.equals("18"))
		{
			img = new Image(AppBundle.INSTANCE.ligne3());
		}
		else if(id.equals("4"))
		{
			img = new Image(AppBundle.INSTANCE.ligne4());
		}
		else if(id.equals("5"))
		{
			img = new Image(AppBundle.INSTANCE.ligne5());
		}
		else if(id.equals("6"))
		{
			img = new Image(AppBundle.INSTANCE.ligne6());
		}
		else if(id.equals("7") || id.equals("16")|| id.equals("17"))
		{
			img = new Image(AppBundle.INSTANCE.ligne7());
		}
		else if(id.equals("8"))
		{
			img = new Image(AppBundle.INSTANCE.ligne8());
		}
		else if(id.equals("9"))
		{
			img = new Image(AppBundle.INSTANCE.ligne9());
		}
		else if(id.equals("10") || id.equals("11"))
		{
			img = new Image(AppBundle.INSTANCE.ligne10());
		}
		else if(id.equals("12"))
		{
			img = new Image(AppBundle.INSTANCE.ligne11());
		}
		else if(id.equals("13"))
		{
			img = new Image(AppBundle.INSTANCE.ligne12());
		}
		else if(id.equals("14"))
		{
			img = new Image(AppBundle.INSTANCE.ligne13());
		}
		else if(id.equals("15")) {
			
			img = new Image(AppBundle.INSTANCE.ligne14());
		}
		
		return img;
	}
	
	
}
